{% extends "layout-settings.html" %}
{% set active_page = "controller" %}
{% set active_settings = "controller" %}
{% set help_page = ["https://kizniche.github.io/Mycodo/Configuration-Settings/#controller-settings", dict_translation['settings']['title'] + ': ' + dict_translation['controller']['title']] %}

{% block title %} - {{dict_translation['settings']['title'] + ': ' + dict_translation['controller']['title']}}{% endblock %}

{% block settings %}
  <!-- Route: /settings/controller -->
  <div class="container">
    <h3 style="text-align: right; padding-bottom: 1.3em;"><a href="https://kizniche.github.io/Mycodo/Configuration-Settings/#controller-settings" target="_blank"><span style="font-size: 16px" class="fas fa-question-circle"></span></a> {{_('Function Settings')}}</h3>

    <h3>{{_('Import Function Module')}}</h3>

    <p>This will allow importing a function module file.</p>

    <form method="post" action="/settings/function" enctype=multipart/form-data>
    {{form_controller.csrf_token}}
    <div class="form-inline">
      <div class="form-group filecontroller filecontroller-new" data-provides="filecontroller">
        <span class="btn btn-sm btn-file"><input id="import_controller_file" name="import_controller_file" type="file" /></span>
      </div>
      <div class="form-group">
        {{form_controller.import_controller_upload(class_='btn btn-primary')}}
      </div>
    </div>
    </form>

    {% if dict_controllers %}

    <hr>

    <h3>{{_('Imported Function Modules')}}</h3>

    <div class="table-responsive">
      <table class="table">
        <tr>
          <td>ID</td>
          <td>{{_('Name')}}</td>
          <td></td>
        </tr>

      {% for each_controller in dict_controllers %}

      <form method="post" action="/settings/function">
      {{form_controller_delete.csrf_token}}
      {{form_controller_delete.controller_id(value=each_controller)}}

        <tr>
          <td>{{each_controller}}</td>
          <td>{{dict_controllers[each_controller]['function_name']}}</td>
          <td>
            <div class="col-12 small-gutters">
              {{form_controller_delete.delete_controller(class_='btn btn-primary btn-block', **{'onclick':'return confirm("Are you sure you want to delete this?")'})}}
            </div>
          </td>
        </tr>

      </form>

    <div style="clear: both; padding: 0.5em 0;"></div>

      {% endfor -%}

      </table>
    </div>

    {% endif %}

  </div>

{% endblock %}
